<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function find(n, trust) {
      let in_list = new Array(n + 1).fill(0)
      let out_list = new Array(n + 1).fill(0)
      for (const item of trust) {
        in_list[item[1]]++
        out_list[item[0]]++
      }
      for (let i = 1; i <= n; i++)
        if (in_list[i] === n - 1 && out_list[i] === 0)
          return i
      return -1
    };
    console.log(find(n = 2, trust = [[1, 2]]));
  </script>
</body>

</html>